package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.TsLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"all"})
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;


    /**
     * 处理用户购买记录
     * @param userPaidRecordVo
     * @return
     */
//    @Operation(summary = "处理用户购买记录")
//    @PostMapping("/savePaidRecord")
//    Result savePaidRecord(@RequestBody UserPaidRecordVo userPaidRecordVo){
//        Boolean record=userInfoService.savePaidRecord(userPaidRecordVo);
//        return record?Result.ok():Result.fail();
//    }
    @Operation(summary = "处理用户购买记录")
    @PostMapping("/savePaidRecord")
    public Result savePaidRecord(@RequestBody UserPaidRecordVo userPaidRecordVo){
        //	调用服务层方法
        Boolean flag = userInfoService.savePaidRecord(userPaidRecordVo);
        //	返回数据
        return flag ? Result.ok() : Result.fail();
    }
    /**
     * 获取专辑已支付的声音Id集合列表
     * @param albumId
     * @return
     */
    @Operation(summary = "获取专辑已支付声音Id集合列表")
    @TsLogin
    @GetMapping("/findUserPaidTrackList/{albumId}")
    public Result<List<Long>> findUserPaidTrackList(@PathVariable Long albumId){
        //	获取用户Id
        Long userId = AuthContextHolder.getUserId();
        //	调用服务层方法;
        List<Long> list = userInfoService.findUserPaidTrackList(userId,albumId);
        //	返回数据
        return Result.ok(list);
    }

    /**
     * 判断用户是否购买过专辑
     *
     * @param albumId
     * @return
     */
    @TsLogin
    @Operation(summary = "判断用户是否购买过专辑")
    @GetMapping("/isPaidAlbum/{albumId}")
    Result<Boolean> isPaidAlbum(@PathVariable("albumId") Long albumId) {
        Long userId = AuthContextHolder.getUserId();
        Boolean result = userInfoService.isPaidAlbum(userId, albumId);
        return Result.ok(result);
    }

    /**
     * 判断用户是否购买声音列表或专辑
     *
     * @param albumId
     * @param trackIdNeedPaidList
     * @return
     */
    @TsLogin
    @Operation(summary = "判断用户是否购买声音")
    @PostMapping("/userIsPaidTrack/{albumId}")
    Result<Map<Long, Integer>> userIsPaidTrack(@PathVariable("albumId") Long albumId, @RequestBody List<Long> trackIdNeedPaidList) {
        //需要一个用户id
        Long userId = AuthContextHolder.getUserId();
        Map<Long, Integer> map = userInfoService.userIsPaidTrack(albumId, trackIdNeedPaidList, userId);
        return Result.ok(map);
    }

    /**
     * 根据userId 获取到用户信息
     *
     * @param userId
     * @return
     */
    @Operation(summary = "根据userId 获取到用户信息")
    @GetMapping("/getUserInfoVo/{userId}")
    public Result<UserInfoVo> getUserInfo(@PathVariable Long userId) {
        UserInfoVo userInfoVo = userInfoService.getUserInfo(userId);
        //	返回数据
        return Result.ok(userInfoVo);
    }
}

